<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>register</title>

    <script src="../JQuery/JQuery-2.1.4.min.js"></script>
</head>
<body>

    <h2>register</h2>
    <hr>

    <div id="registerDiv">
        <div>
            username:
            <input type="text" id="userName" placeholder="please intput your username!">
        </div>

        <br>
        <div>
            password:
            <input type="password" id="password" placeholder="please intput your password!">
        </div>

        <br>
        <div>
            confirmPassword:
            <input type="password" id="confirmPassword" placeholder="please intput your password again!">
        </div>

        <br>
        <button id="confirm">注册</button>
        <button id="conceal">取消</button>
    </div>

    <div><input id="test" type="button" value="警告" hidden></div>

    <div><input id="test1" type="button" value="click" hidden></div>

    <script>
        $('#test1').on("click",function (){
            alert(sessionStorage.getItem("some"));
        })


        $('#test').on("click",function (){
            sessionStorage.setItem("currentPath","/files");
            alert(sessionStorage.getItem("currentPath"));
            var url = "/test";
            $.ajax({
                type: "post",
                url: url,
                success:function (){
                    // alert("some" + sessionStorage.getItem("some"));
                    // sessionStorage.setItem("some","haha");
                }
                // success:function (data){
                //     alert(data);
                //     if(data == "ok"){
                //         location.href = "login.html";
                //     }
                // }
            })
        })

        $('#conceal').on("click",function (){
            alert("click conceal!");
            location.href = "login.html";
        })

        $('#confirm').on("click",function (){
            alert("click confirm!");
            var username = $('#userName').val();
            var password = $('#password').val();
            var confirmPassword = $('#confirmPassword').val();

            var d = {
                "username": username,
                "password": password,
                "confirmPassword": confirmPassword
            }
            var url = "/register";
            $.ajax({
                type:"post",
                url:url,
                data:d,
                success:function (data){
                    // alert(data.status);
                    if(data.status == "ok"){
                        alert("注册成功！")
                        location.href = "login.html";
                    }else if (data.status == "userexist"){
                        alert("用户名已存在！")
                        jQuery('#userName').val('');
                        jQuery('#password').val('');
                        jQuery('#confirmPassword').val('');
                    }else{
                        alert("两次输入密码不一致！！")
                        // jQuery('#userName').val('');
                        jQuery('#password').val('');
                        jQuery('#confirmPassword').val('');
                    }
                }
            })
        })

    </script>

</body>
</html>